package org.zhangjq.myproject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述
 *
 * @author: zhangjq
 * @date: 2024年01月17日 14:09
 */
@RestController
@RequestMapping(value = "/xxService/api")
public class DemoController {

    @Autowired
    private Environment environment;

//    /**
//     * 动态设置方法上的注解的参数值
//     * @throws NoSuchMethodException
//     */
//    @PostConstruct
//    public void init() throws NoSuchMethodException {
//        RequestMapping mapping = this.getClass().getMethod("save").getAnnotation(RequestMapping.class);
//        // 获取参数值
//        String value = environment.resolvePlaceholders(mapping.value()[0]);
//        String name = environment.resolvePlaceholders(mapping.name());
//
//        // 输出
//        System.out.println("value-------->" + value);
//        System.out.println("name-------->" + name);
//    }

    /**
     * 测试方法
     */
    @RequestMapping(value = "${service.api.url.method}", name = "方法上动态参数设置", method = RequestMethod.GET)
    @IgnoreApiValid(value = "${api.fhl.appKey}")
    public String save() {
        System.out.println("我已经进入save()方法。。。。。。。。。。。");
        String s1 = environment.resolvePlaceholders("${service.api.url.method}");
        String s2 = environment.resolvePlaceholders("${api.fhl.appKey}");
        System.out.println("s1 -----> " + s1);
        System.out.println("s2 -----> " + s2);
        return "再次请求成功！";
    }

}